#pragma once

#include <math.h>

typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef __int64		int64;

typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned __int64 uint64;

#define PI 3.1415926536f
#define DEG2RAD (PI/180.0f)
#define RAD2DEG (180/PI)

__forceinline float clamp(float x,float m,float M)
{
	if (x<m) return m;
	if (x>M) return M;
	return x;
}
__forceinline int clamp(int x,int m,int M)
{
	if (x<m) return m;
	if (x>M) return M;
	return x;
}

template <typename T> T sign(T t){return t>0 ? T(1) : T(-1);}


template<typename T>
inl void setmin(T& srcdst, T cmp)
{
	if (cmp<srcdst) srcdst=cmp;
}

template<typename T>
inl void setmax(T& srcdst, T cmp)
{
	if (cmp>srcdst) srcdst=cmp;
}

template<int digit>
inl float pow10()
{
	return 10*pow10<digit-1>();
}

template<>
inl float pow10<0>()
{
	return 1;
}

template<int digit>
inl float clamptodigit(float f)
{
	return ((floorf)(f*pow10<digit>()+0.49f))/pow10<digit>();
}

inl float sqr(float f)
{
	return f*f;
}

inl int sqr(int i)
{
	return i*i;
}